<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <button>Get请求</button>
    <button>发起post请求</button>

    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.0/axios.js"></script>
    <script type="text/javascript">
      document.getElementsByTagName('button')[0].addEventListener(
        'click',
        function () {
          var url = 'http://www.liulongbin.top:3006/api/get';
          axios
            .get(url, { params: { name: 'zs', age: 20 } })
            .then(function (res) {
              console.log(res.data);
            })
        },false)

      document.getElementsByTagName('button')[1].addEventListener(
      'click',
      function () {
        var url = 'http://www.liulongbin.top:3006/api/post';
        axios
          .post(url, { address: '北京', location: '顺义区' } )
          .then(function (res) {
            console.log(res.data);
          })
      },false)

      axios({
        method: 'get',
        url: 'http://www.liulongbin.top:3006/api/get',
        params: {name: 'ls', age: 23}
      }).then(function(res){
        console.log(res.data);
      })

      axios({
        method: 'post',
        url: 'http://www.liulongbin.top:3006/api/post',
        data: { address: '上海', location: '黄浦区' },
      }).then(function(res){
        console.log(res.data);
      })

      
    </script>
  </body>
</html>
